module FES1DL2_m
use AFES_m
use Mesh1DL2_m

type, extends(AFES) :: FES1DL2
    type(mesh1DL2), pointer :: mesh1D
contains
    procedure :: getInfoPerNode => getInfoPerNode1DL2
    procedure :: getInfoPerElement => getInfoPerElement1DL2
    procedure :: getInfoPerBoundary => getInfoPerBoundary1DL2
end type

contains

subroutine getInfoPerNode1DL2(this, i, coord)
    implicit none
    class(FES1DL2), intent(in) :: this
    integer, intent(in) :: i
    real*8, intent(out) :: coord(:)
    
    type(mesh1DL2), pointer :: mesh1D
    mesh1D => this%mesh1D
    coord = mesh1D%nodes(i)%x
end subroutine

subroutine getInfoPerElement1DL2(this, i, ele, label, coord)
    implicit none
    class(FES1DL2), intent(in) :: this
    integer, intent(in) :: i
    integer, intent(out) :: ele(:), label
    real*8, intent(out) :: coord(:, :)
    
    type(mesh1DL2), pointer :: mesh1D
    mesh1D => this%mesh1D
    ele = mesh1D%elements(i)%idx
    label = mesh1D%elements(i)%num
    coord(:, 1) = mesh1D%nodes(ele)%x(1)
end subroutine

subroutine getInfoPerBoundary1DL2(this, i, ele, label, coord)
    implicit none
    class(FES1DL2), intent(in) :: this
    integer, intent(in) :: i
    integer, intent(out) :: ele(:), label
    real*8, intent(out) :: coord(:, :)
    
    type(mesh1DL2), pointer :: mesh1D
    mesh1D => this%mesh1D
    ele = mesh1D%boundarys(i)%idx
    label = mesh1D%boundarys(i)%num
    coord(:, 1) = mesh1D%nodes(ele)%x(1)
end subroutine

end module